package com.ht.api.call.func.impl.ad;

import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.ht.api.bean.AjaxResult;
import com.ht.api.bean.LoginBean;
import com.ht.api.business.ad.PlanHelper;
import com.ht.api.call.func.IFunctionCall;
import com.ht.api.db.Db;
import com.ht.api.db.DbList;
import com.ht.api.db.Entity;
import com.ht.api.service.PlanService;
import lombok.extern.slf4j.Slf4j;

/**
 * 通过广告查询计划策略
 */
@Slf4j
public class PlanQueryWithAdFunctionCall implements IFunctionCall {

	@Override
	public String getName() {
		return "通过广告查询计划策略";
	}

	@Override
	public JSONObject execute(LoginBean me, JSONObject param, AjaxResult result) {
		DbList list = result.getRecords();

		for (Entity campaignItem : list) {
			Entity plan = campaignItem.getBean("mapper_campaign_id", Entity.class);
			PlanService.formatPlan(me.getDataSource(), plan);
			campaignItem.putAll(plan);
		}

		return JSONUtil.createObj();
	}

}
